package com.originskyseed.platform.user.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.mapper.TradeUnionMapper;
import com.originskyseed.platform.user.model.TradeUnion;
import com.originskyseed.platform.user.service.ITradeUnionService;

/**
 * 公会信息Service接口实现类（OSI_TRADE_UNION）
 *
 * @author tangwanghui
 */
@DubboService
@Component("tradeUnionService")
public class TradeUnionServiceImpl implements ITradeUnionService {

	@Resource
	private TradeUnionMapper tradeUnionMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.tradeUnionMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.tradeUnionMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(TradeUnion record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.tradeUnionMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(TradeUnion record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.tradeUnionMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(TradeUnion record) throws Exception {
		record.setUpdateTime(new Date());
		return this.tradeUnionMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(TradeUnion record) throws Exception {
		record.setUpdateTime(new Date());
		return this.tradeUnionMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByUserId(TradeUnion record) throws Exception {
		record.setUpdateTime(new Date());
		return this.tradeUnionMapper.updateByUserId(record);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public TradeUnion selectByPrimaryKey(String id) throws Exception {
		return this.tradeUnionMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<TradeUnion> selectList(TradeUnion record) throws Exception {
		return this.tradeUnionMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<TradeUnion> selectListByPage(Map<String, Object> params, BasePage<TradeUnion> page) throws Exception {
		params.put("page", page);
		List<TradeUnion> list = this.tradeUnionMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 开放平台选择公会 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<TradeUnion> selectTradeUnionList(Map<String, Object> params, BasePage<TradeUnion> page) throws Exception {
		params.put("page", page);
		List<TradeUnion> list = this.tradeUnionMapper.selectTradeUnionList(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询记录
	 *
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	@Override
	public TradeUnion selectByUserId(String userId) throws Exception {
		return this.tradeUnionMapper.selectByUserId(userId);
	}

	/**
	 * 查询公会id是否存在
	 *
	 * @param tradeUnionIds
	 * @return
	 * @throws Exception
	 */
	public List<String> selectTradeUnionIds(List<String> tradeUnionIds) throws Exception {
		return this.tradeUnionMapper.selectTradeUnionIds(tradeUnionIds);
	}

	/**
	 * 插入记录
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(List<TradeUnion> list) throws Exception {
		return this.tradeUnionMapper.insertBatch(list);
	}
}
